var RunLayer_08 = cc.Layer.extend({
	arr:null,
	scene:null,
	clock:null,
	ctor:function (parent) {
		this._super();
		this.scene = parent;
		this.scene.addChild(this, 10);
		gg.main = this;
		this.init();
	},
	init:function () {
		gg.scoreCheck = true;
		this.callNext = cc.callFunc(function(){
			gg.flow.next();
		}, this);
		this.callKill = cc.callFunc(function(p){
			var seq = cc.sequence(cc.fadeOut(0.5),cc.callFunc(function(){
				p.removeFromParent(true);	
			}, this));
			p.runAction(seq);
		}, this); 
		
		this.callNext.retain();
		this.callKill.retain();
		//时钟
		this.clock = new Clock(this);
		// 物品库
		this.lib = new Lib(this);
		this.lib.loadBg([
		                 {tag:TAG_LIB_CONICAL},
		                 {tag:TAG_LIB_YIMI,checkright:true},
		                 {tag:TAG_LIB_SAND},
		                 {tag:TAG_LIB_SAI,checkright:true},
		                 {tag:TAG_LIB_CYLINDER},
		                 {tag:TAG_LIB_SHELF},
		                 {tag:TAG_LIB_INJECTOR,checkright:true},
		                 {tag:TAG_LIB_LAMP},
		                 {tag:TAG_LIB_TESTTUBE},
		                 {tag:TAG_LIB_VOLUMETRIC}
		                 ]);
		//实战中，默认出lib，得分字不出
		ll.tip.scoreLabel.setVisible(false);
		//注射器
		var inoculator = new Inoculator(this);
		inoculator.setPosition(cc.p(700,300));
		//乙醚
		this.loadYiMi();
		//橡木塞
		this.loadMuSai();
	},
	checkVisible:function(next){
		//是否可见
		var checkVisible = [];
		var inoculator = this.getChildByTag(TAG_INOCULATOR_NODE);
		var yimi = this.getChildByTag(TAG_YIMI);
		var musai = this.getChildByTag(TAG_XIANGPISAI);
		var show = ll.run.getChildByTag(TAG_SHOW);
		checkVisible.push(inoculator,yimi,musai,show);

		for(var i in checkVisible){
			if(checkVisible[i] !== null){				
				checkVisible[i].setVisible(next);				
			}			
		}
	},
	loadYiMi:function(){
		var yimi =  new Button(this, 11, TAG_YIMI, "#lib/yimi.png",this.callback);//乙醚 
		yimi.setPosition(cc.p(420,160));
		yimi.setScale(0.08);
		yimi.setVisible(false);

		var label = new cc.LabelTTF("乙醚",gg.fontName,20);
		label.setPosition(yimi.width/2,yimi.height*0.5);
		label.setScale(10);
		yimi.addChild(label);
	},
	loadMuSai:function(){
		var xiangpisai =  new Button(this, 11, TAG_XIANGPISAI, "#lib/sai.png",this.callback);//橡皮塞
		xiangpisai.setPosition(cc.p(800,110));
		xiangpisai.setRotation(180);
		xiangpisai.setScale(0.3);
		xiangpisai.setVisible(false);
	},
	loadInLib:function(obj, pos, tarPos,delay){
		obj.setPosition(pos);
		if(delay == null){
			delay = 1;
		}
		var ber = $.bezier(pos, tarPos, delay);
		var seq = cc.sequence(ber, this.callNext);
		obj.runAction(seq);
	},
	kill:function(obj){
		var fade = cc.fadeTo(0.5,0);
		var func = cc.callfunc(function(){
			obj.removeFromParent(true);
		},this);
		var seq = cc.sequence(fade,func);
		obj.runAction(seq)
	},
	
	callback:function (p){
		var func = cc.callFunc(this.actionDone, this);
		var action=gg.flow.flow.action;
		switch(p.getTag()){
		case TAG_XIANGPISAI:
			var seq = cc.sequence(cc.moveTo(1,cc.p(600,110)),cc.delayTime(0.5),cc.callFunc(function(){
				this.flowNext();
			},this));
			p.runAction(seq);
			var inoculator = ll.run.getChildByTag(TAG_INOCULATOR_NODE);
			inoculator.runAction(cc.spawn(cc.moveTo(1.2,cc.p(600,280)),cc.rotateTo(1.2,-90)));
			
			var yimi = inoculator.getChildByTag(TAG_SHOW);
			yimi.runAction(cc.spawn(cc.moveTo(1.2,cc.p(-90,0)),cc.rotateTo(1.2,90)));
		break;
		}
	},
	flowNext:function(){
		gg.flow.next();
	},
	onExit:function(){
		this._super();
		this.callNext.release();
		this.callKill.release();
	}
});